package edu.uwm.RobberKnight.Controller;

import java.awt.Point;
import java.util.LinkedList;

import edu.uwm.RobberKnight.Model.Board;
import edu.uwm.RobberKnight.Model.GameState;
import edu.uwm.RobberKnight.Model.Player;
import edu.uwm.RobberKnight.Model.RobberKnightsGame;
import edu.uwm.RobberKnight.Model.Tile;

public class RobberKnightsController {
	private RobberKnightsGame _game;
	private Tile _selectedTile;
	LinkedList<Player> _cachedPlayers;
	public RobberKnightsController() {
		newGame();
	}
	
	public LinkedList<Tile> getTiles() {
		return _game.getBoard().getTiles();
	}
	
	public void newGame() {
		_game = new RobberKnightsGame();
	}
	
	public void addPlayer(String name, int age) {
		_game.addPlayer(name, age);
	}
	
	public LinkedList<Player> getPlayers() {
		return _cachedPlayers;
	}
	
	public int getBoardWidth() {
		return _game.getBoard().getWidth();
	}
	
	public int getBoardHeight() {
		return _game.getBoard().getHeight();
	}

	@SuppressWarnings("unchecked")
	public void startGame() {
		_game.startGame();
		_cachedPlayers = (LinkedList<Player>) _game.getPlayers().clone();
	}
	
	public String[] getLogs() {
		return _game.getLogs();
	}
	
	public Player getCurrentPlayer() {
		return _game.getCurrentPlayer();
	}
	
	public LinkedList<Point> getValidTileLocs() {
		return _game.getBoard().getValidLocs();
	}
	
	public LinkedList<Tile> getValidKnightMoves() {
		return _game.getBoard().getValidMoves();
	}
	
	public void setSelectedTile(Tile tile) {
		_selectedTile = tile;
	}
	
	public Tile getSelectedTile() {
		return _selectedTile;
	}
	
	public boolean placeTile(int x, int y) {
		boolean success = _game.getBoard().placeTile(_selectedTile, x, y);
		if(success)
			_selectedTile = null;
		return success;
	}
	
	public boolean placeKnight(Tile tile) {
		return _game.getBoard().placeKnights(tile, getCurrentPlayer());
	}
	
	public GameState getState() {
		return _game.getState();
	}
	
	public boolean nextTurn() {
		return _game.nextTurn();
	}

	public boolean isKnightsPlayable() {
		return _game.getBoard().isKnightsPlayable();
	}
	
	public Board getBoard() {
		return _game.getBoard();
	}
	
}
